package com.example.bobo.yuejian322.Fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.bobo.yuejian322.Activity.BaomingActivity;
import com.example.bobo.yuejian322.Activity.GuanyuYuejianActivity;
import com.example.bobo.yuejian322.Activity.LoveActivity;
import com.example.bobo.yuejian322.Activity.OrderActivity;
import com.example.bobo.yuejian322.Interfa.LoginSeverice;
import com.example.bobo.yuejian322.Interfa.MySeverice;
import com.example.bobo.yuejian322.R;
import com.example.bobo.yuejian322.base.BaseFragment;
import com.example.bobo.yuejian322.bean.GuanyuYuejian;
import com.example.bobo.yuejian322.bean.Login;
import com.example.bobo.yuejian322.bean.My;
import com.squareup.picasso.Picasso;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * A simple {@link Fragment} subclass.
 */
public class MyFragment extends BaseFragment {

    private TextView Myname;
    private ImageView photo;
    private TextView GuanyuYuanjian;
    private RadioGroup radioGroup;
    private RadioButton guanzhu;
    Intent intent=new Intent();
    public MyFragment() {
        // Required empty public constructor
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        GuanyuYuanjian= (TextView) view.findViewById(R.id.guanyu_Yuejian);
        radioGroup= (RadioGroup) view.findViewById(R.id.radioGroup_my);
        guanzhu= (RadioButton) view.findViewById(R.id.radio_guanzu);
        Myname= (TextView) view.findViewById(R.id.myname);
        photo= (ImageView) view.findViewById(R.id.imageView_myphoto);

        //关于约健的跳转监听
         guanyuyuejian();
        //对radiogroup的监听
        RadioGroup();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://172.24.10.175/workout/api.php/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        MySeverice mySeverice = retrofit.create(MySeverice.class);

        Call<My> call = mySeverice.my(getUserId(), 191);
        call.enqueue(new Callback<My>() {
            @Override
            public void onResponse(Call<My> call, Response<My> response) {
                My my =response.body();
                if (getActivity() != null) {
                  Myname.setText(my.getUser_name());
                    guanzhu.setText("关注");
                    Object pic=my.getPhoto();

                    if (pic!=null){
                        Picasso.with(getContext()).load("http://172.24.10.175/workout/Uploads/"+pic).error(R.drawable.image1).into(photo);
                    }
                }
            }
            @Override
            public void onFailure(Call<My> call, Throwable t) {

            }
        });





    }


    //关于约健的监听
    private  void guanyuyuejian(){



        GuanyuYuanjian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent =new Intent();
                intent.setClass(getActivity(), GuanyuYuejianActivity.class);
                startActivity(intent);
            }
        });





    }


    private void RadioGroup(){
   //对radiogroup的监听
       radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(RadioGroup group, int checkedId) {
               switch (checkedId) {
                   case R.id.radio_fatie:

                       break;

                   case R.id.radio_guanzu:
                       intent.setClass(getActivity(), LoveActivity.class);
                       startActivity(intent);
                       break;


                   case R.id.radio_dingdan:


                       intent.setClass(getActivity(), OrderActivity.class);
                       startActivity(intent);

                       break;


               }

           }
       });



   }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_my, container, false);

    }



}
